<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/17
 * Time: 上午8:56
 */

namespace app\doctor\controller;


use think\Controller;
use app\common\model\Base;

class Login extends Basecontroller
{
    /**
     * 登录首页
     */
    protected $noNeedLogin = ['index','logout'];


    /**
     * 登录页
     */
    public function index()
    {

        if ($this->request->isPost()) {
            $account = $this->request->param('username');
            $password = $this->request->param('password');

            if ($doctor = $this->doctor->login($account, $password)) {

                $arr_content['string'] = $doctor['username'].'登录';
                $arr_content['opera_type'] = 5;
                $model = new Base();
                $model->add_admin_log($doctor['id'],$arr_content,$doctor['id'],'doctor','用户',2);
                $this->success("登录成功", url('index/index'));

            } else {
                $this->error($this->doctor->getError());
            }
        }

        return $this->fetch();
    }

    /**
     * 注销登录
     */
    function logout()
    {
        //注销本站
        $this->doctor->logout();

        return $this->redirect('login/index');
    }


}